package cn.com.egova.skinapplication.skin.attr;

import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import cn.com.egova.skinapplication.skin.ResourceManager;
import cn.com.egova.skinapplication.skin.SkinManager;

/**
 * Created by yuanchao on 2017/3/12.
 */

public enum SkinAttrType {
    BACKGROUND("background") {
        @Override
        public void apply(View view, String mResName) {
            Drawable drawable = getResourceManager().getDrawableByResName(mResName);
            if (drawable != null) {
                view.setBackgroundDrawable(drawable);
            }
        }
    }, SRC("src") {
        @Override
        public void apply(View view, String mResName) {
            Drawable drawable = getResourceManager().getDrawableByResName(mResName);
            if (view instanceof ImageView) {
                ImageView imageView = (ImageView) view;
                if (drawable != null) {
                    imageView.setImageDrawable(drawable);
                }
            }
        }
    }, TEXT_COLOR("textColor") {
        @Override
        public void apply(View view, String mResName) {
            ColorStateList colorStateList = getResourceManager().getColorByResName(mResName);
            if (view instanceof TextView) {
                if (colorStateList != null) {
                    ((TextView) view).setTextColor(colorStateList);
                }
            }
        }
    };

    private String resType;

    SkinAttrType(String type) {
        resType = type;
    }

    public String getResType() {
        return resType;
    }


    public abstract void apply(View view, String mResName);


    public ResourceManager getResourceManager() {
        return SkinManager.getInstance().getResourceManager();
    }
}
